package com.care.inquiry.server.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.care.inquiry.common.domain.Chat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.care.common.log.annotation.Log;
import com.care.common.log.enums.BusinessType;
import com.care.common.security.annotation.RequiresPermissions;
import com.care.inquiry.server.service.IChatService;
import com.care.common.core.web.controller.BaseController;
import com.care.common.core.domain.Result;
import com.care.common.core.utils.poi.ExcelUtil;
import com.care.common.core.web.page.TableDataInfo;

/**
 * 聊天记录Controller
 *
 * @author care
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/inquiry")
public class ChatController extends BaseController
{
    @Autowired
    private IChatService chatService;

    /**
     * 查询聊天记录列表
     */
    @RequiresPermissions("inquiry:inquiry:list")
    @GetMapping("/list")
    public TableDataInfo list(Chat chat)
    {
        startPage();
        List<Chat> list = chatService.selectChatList(chat);
        return getDataTable(list);
    }

    /**
     * 导出聊天记录列表
     */
    @RequiresPermissions("inquiry:inquiry:export")
    @Log(title = "聊天记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Chat chat)
    {
        List<Chat> list = chatService.selectChatList(chat);
        ExcelUtil<Chat> util = new ExcelUtil<Chat>(Chat.class);
        util.exportExcel(response, list, "聊天记录数据");
    }

    /**
     * 获取聊天记录详细信息
     */
    @RequiresPermissions("inquiry:inquiry:query")
    @GetMapping(value = "/{chatId}")
    public Result getInfo(@PathVariable("chatId") Integer chatId)
    {
        return success(chatService.selectChatByChatId(chatId));
    }

    /**
     * 新增聊天记录
     */
    @RequiresPermissions("inquiry:inquiry:add")
    @Log(title = "聊天记录", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Chat chat)
    {
        return toAjax(chatService.insertChat(chat));
    }

    /**
     * 修改聊天记录
     */
    @RequiresPermissions("inquiry:inquiry:edit")
    @Log(title = "聊天记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Chat chat)
    {
        return toAjax(chatService.updateChat(chat));
    }

    /**
     * 删除聊天记录
     */
    @RequiresPermissions("inquiry:inquiry:remove")
    @Log(title = "聊天记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chatIds}")
    public Result remove(@PathVariable Integer[] chatIds)
    {
        return toAjax(chatService.deleteChatByChatIds(chatIds));
    }
}
